package imageReader;

import java.awt.image.BufferedImage;

public class ImagePixelReader {

	public static int[] getRGB(BufferedImage image, int x, int y) {
		int[] rgb = new int[3];
		int pixel = image.getRGB(x, y);
		rgb[0] = (pixel & 0xff0000) >> 16;
		rgb[1] = (pixel & 0xff00) >> 8;
		rgb[2] = (pixel & 0xff);
		
		rgb[0] = shrinkHash(rgb[0]);
		rgb[1] = shrinkHash(rgb[1]);	
		rgb[2] = shrinkHash(rgb[2]);

		return rgb;
	}
	
	private static int shrinkHash(int value) {
		double partitonButton = (double)254/(double)40;
		double partitionNum = value/partitonButton;
		return (int)(Math.floor(partitionNum) * partitonButton);
	}

}
